﻿@model List<System_User_Info>
@{
    ViewBag.Title = "MenuList";
    Layout = "~/Views/Shared/_Layout_List.cshtml";
}
<div class="main-container">
    <div class="toolbar">
        <button class="btn btn-add" type="button" onclick="CategoryFunFirst();"><i class="icon-plus"></i>&nbsp;新增首级功能</button>
        <button class="btn" type="button" onclick="CategoryFun();"><i class="icon-plus"></i>&nbsp;新增子级功能</button>
        <button class="btn" type="button" onclick="CategoryModify();"><i class="icon-edit"></i>&nbsp;编辑功能菜单</button>
        <button class="btn" type="button" onclick="Del();"><i class="icon-minus"></i>&nbsp;删除</button>
    </div>
    <div style="clear: both"></div>
    <div class="table-responsive">
        <ul id="treeDemo" class="ztree" style="background-color: white; width: auto; height: auto; border: 0px; overflow-y: visible"></ul>
    </div>
</div>
@section JsPlaceHolder
{
    <script src="~/Content/js/zTree_v3/js/jquery.ztree.all-3.5.min.js"></script>
    <script type="text/javascript">
        ////树开始
        var url = "/System/GetSystemTreeJson?menuId=0";
        var setting = {
            async: {
                enable: true,
                url: url,
                autoParam: ["id", "pId", "name"]
            },
            check: {
                enable: false,
                chkboxType: { "Y": "", "N": "" }
            },
            view: {
                dblClickExpand: false,
                showLine: true,
                showIcon: true
            },
            callback: {
                onAsyncSuccess: zTreeOnAsyncSuccess
            }
        };
        function zTreeOnAsyncSuccess() {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            zTree.expandAll(true);
        }
        $(document).ready(function () {
            $.fn.zTree.init($("#treeDemo"), setting);
        });
        //树结束

        //添加系统功能
        function CategoryFun() {
            var zTree1 = $.fn.zTree.getZTreeObj("treeDemo");
            var tmp = zTree1.getSelectedNodes();
            if (tmp[0] == null) {
                layer.msg('请选择要操作的项！', { icon: 5, time: 1000, shade: 0.3 });
            } else {
                page = "@Url.Action("MenuAdd", "System")?parentId=" + tmp[0].id + "&parentName=" + tmp[0].name,
                AlertModelFrame(page, '新增子级功能');
            }
        }
        //添加首级系统功能
        function CategoryFunFirst() {
            page = "@Url.Action("MenuAdd", "System")?parentId=0",
            AlertModelFrame(page, '新增首级功能');
        }

        //编辑系统功能
        function CategoryModify() {
            var zTree1 = $.fn.zTree.getZTreeObj("treeDemo");
            var tmp = zTree1.getSelectedNodes();
            if (tmp[0] == null) {
                layer.msg('请选择要操作的项！', { icon: 5, time: 1000, shade: 0.3 });
            } else {
                page = "@Url.Action("MenuEdit", "System")?id=" + tmp[0].id + "&parentName=" + tmp[0].name,
                AlertModelFrame(page, '编辑功能菜单');
            }
        }
        //删除，改变状态操作
        function Del() {
            var zTree1 = $.fn.zTree.getZTreeObj("treeDemo");
            var tmp = zTree1.getSelectedNodes();
            if (tmp[0] == null) {
                layer.msg('请选择要操作的项！', { icon: 5, time: 1000, shade: 0.3 });
            } else {
                //删除操作
                var ids = '';
                var idArr = [];
                $.each(tmp, function (i, obj) {
                    idArr.push(obj.id);
                });
                layer.confirm('确定删除选中的系统功能？', { icon: 3, title: '提示' }, function () {
                    var url = "/System/DelMenu?ids=" + idArr.join(',');
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: "",
                        success: function (msg) {
                            if (msg.Status) {
                                layer.msg(msg.Message, { icon: 6, time: 700, shade: 0.3 }, function () { window.location.reload(true); });
                            } else {
                                layer.msg('删除失败', { icon: 5, time: 700, shade: 0.3 }, function () { window.location.reload(true); });
                            }
                        }
                    });
                });
            }
        }
    </script>
}